﻿@model Hospital
@{
    ViewBag.Title = "添加医院";
    Layout = "~/Views/Shared/Master.cshtml";
}

@{Html.Telerik().Window().Name("AddHospitalWindow").Title("添加医院").HtmlAttributes(new { @class = "ContentWindow" })
    .Buttons(buttons => buttons.Clear())
    .Content(
@<text>
@{using (Ajax.BeginForm<HospitalController>(c => c.HospitalAdd(null),
    new AjaxOptions { OnBegin = "BeforeSend", OnSuccess = "OnSuccess", OnFailure = "OnError" }))
  {
<table>
    <tr>
        <th>医院编号</th>
        <td>
            @Html.HiddenFor(model => model.ID)
            @Html.TextBoxFor(model => model.Code)
        </td>
    </tr>
    <tr>
        <th>医院名称</th>
        <td>@Html.TextBoxFor(model => model.Name)</td>
    </tr>
    <tr>
        <th>登录名</th>
        <td>@Html.TextBox("Members[0].LoginName")</td>
    </tr>
    <tr>
        <th>默认密码</th>
        <td>@Html.TextBox("Members[0].Password", "123456")</td>
    </tr>
    <tr>
        <th>地址</th>
        <td>@Html.TextBoxFor(model => model.Address)</td>
    </tr>
    <tr>
        <th>联系电话</th>
        <td>@Html.TextBoxFor(model => model.Phone)</td>
    </tr>
    <tr>
        <th>E-mail</th>
        <td>@Html.TextBoxFor(model => model.Email)</td>
    </tr>
    <tr>
        <th>网址</th>
        <td>@Html.TextBoxFor(model => model.Website)</td>
    </tr>
    <tr>
        <th>详细介绍</th>
        <td>@Html.TextAreaFor(model => model.Detail)</td>
    </tr>
</table>
        
<input type="submit" value="提交"/>
  }
}
</text>)
    .Render();
}
@{Html.Telerik().Window().Modal(true).Visible(false)
    .Name("adding").Title("系统提示")
    .Buttons(buttons => buttons.Clear())
    .ClientEvents(window => window.OnOpen("OnAddingOpen"))
    .Content(
@<text>
正在添加，请稍后...
</text>)
    .Render();
}
@{Html.Telerik().Window().Modal(true).Visible(false)
    .Name("addError").Title("系统提示")
    .Buttons(buttons => buttons.Close())
    .ClientEvents(window => window.OnOpen("OnAddErrorOpen"))
    .Content(
@<text>
出现错误，请重试！
</text>)
    .Render();
}
<script type="text/javascript">
    function OnAddingOpen() {
        $("#adding").data("tWindow").center();
    }
    function OnAddErrorOpen() {
        $("#addError").data("tWindow").center();
    }
    function BeforeSend() {
        $("#adding").data("tWindow").open();
    }
    function OnSuccess(data) {
        if (data.ID) {
            var url = "@(Url.Action<HospitalController>(c => c.HospitalDetail(Guid.Empty)))";
            url = url.replace("@Guid.Empty", data.ID);
            window.location = url;
        } else {
            $("#addError").data("tWindow").open();
            $("#adding").data("tWindow").close();
        }
    }
    function OnError() {
        $("#addError").data("tWindow").open();
        $("#adding").data("tWindow").close();
    }
    function CheckForm() {
        alert("请输入您姓名!");
        if (document.form.Name.value.length == 0) {
            alert("请输入您姓名!");
            document.form.Name.focus();
            return false;
        }
        return true;
    }
</script>
